﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using HigLabo.Net.Extensions;

namespace HigLabo.Net.Twitter
{
    /// <summary>
    /// 
    /// </summary>
    public class DirectMessage : ResponseObject
    {
        private DateTimeOffset _CreatedAt = DateTimeOffset.Now;
        private String _Text = "";
        private Int64 _ID = 0;
        private Int64 _SenderID = 0;
        private Int64 _RecipientID = 0;
        private String _SenderScreenName = "";
        private String _RecipientScreenName = "";
        private User _SenderUser = null;
        private User _RecipientUser = null;
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset CreatedAt
        {
            get { return _CreatedAt; }
            set { _CreatedAt = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public String Text
        {
            get { return _Text; }
            set { _Text = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public Int64 ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public Int64 SenderID
        {
            get { return _SenderID; }
            set { _SenderID = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public Int64 RecipientID
        {
            get { return _RecipientID; }
            set { _RecipientID = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public String SenderScreenName
        {
            get { return _SenderScreenName; }
            set { _SenderScreenName = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public String RecipientScreenName
        {
            get { return _RecipientScreenName; }
            set { _RecipientScreenName = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public User SenderUser
        {
            get { return _SenderUser; }
            set { _SenderUser = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public User RecipientUser
        {
            get { return _RecipientUser; }
            set { _RecipientUser = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public String IDString { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Entities Entities { set; get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public DirectMessage(String jsonText)
        {
            this.SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public override void SetProperty(string jsonText)
        {
            var d = this.SetData(jsonText);

            this.CreatedAt = d.CastToDateTimeOffset("created_at") ?? this.CreatedAt;
            this.ID = d.ToInt64("id") ?? this.ID;
            this.IDString = d.ToString("id_str");
            this.SenderID = d.ToInt64("sender_id") ?? this.SenderID;
            this.RecipientID = d.ToInt64("recipient_id") ?? this.RecipientID;
            this.Text = d.ToString("text");
            this.SenderScreenName = d.ToString("sender_screen_name");
            this.RecipientScreenName = d.ToString("recipient_screen_name");

            this.SenderUser = new User(d.ToString("sender"));
            this.RecipientUser = new User(d.ToString("recipient"));
        }
    }
}
